package Day2025_03_31;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class LeetCode2311 {
    public boolean evaluateTree(TreeNode root) {
        if (root == null) return true;
        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);
        if (root.left == null) {
            if (root.val == 0) return false;
            else return true;
        } else {
            if (root.val == 2) return left || right;
            else return left && right;
        }
    }
}
